package com.running.base.run.util;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

public class PhoneUtil {

    private static final String REGEX_MOBILE = "(134[0-8]\\d{7})" + "|(" + "((13([0-3]|[5-9]))" + "|149"
            + "|15([0-3]|[5-9])" + "|166" + "|17(3|[5-8])" + "|18[0-9]" + "|19[8-9]" + ")" + "\\d{8}" + ")";

    /**
     * 判断是否是手机号
     * @param mobile 手机号
     */
    public static boolean isMobile(String mobile) {
        return Pattern.matches(REGEX_MOBILE, mobile);
    }


    public static String getMastPhoneNum(String mobile) {
        if (StringUtils.isBlank(mobile)) return "";
        return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
    }
}
